const fs = require('fs');
const path = require('path');



const copy = (src, dist) => {
  fs.readdir(src, (err, paths) => {

    paths && paths.forEach(item => {
      let _src = src + '/' + item;
      let _dist = dist + '/' + item;
      fs.stat(_src, (err, stat) => {
        console.log(stat.isFile())
        if (stat.isDirectory()) {
          exists(_src, _dist)
        } else if (stat.isFile()) {
          console.log(_src)
          fs.readFile(_src, (err, data) => {
            fs.writeFile(_dist, data, (err, res) => {
              console.log('success')
            })
          })
        }
      })
    })
  })
}

const exists = (src, dist) => {
  fs.exists(dist, (exists) => {
    if (exists) {
      copy && copy(src, dist)
    } else {
      fs.mkdir(dist, () => {
        copy && copy(src, dist)
      })
    }
  })
}

exists('./src', './dist')